package com.ruoyi.web.controller.bookkeeping;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.bookkeeping.domain.param.GetBookNewsParam;
import com.ruoyi.bookkeeping.domain.vo.MsgResult;
import com.ruoyi.bookkeeping.domain.vo.TableDataInfoVo;
import com.ruoyi.bookkeeping.util.GetPageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookkeeping.domain.BookNews;
import com.ruoyi.bookkeeping.service.IBookNewsService;

/**
 * 新闻Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/bookkeeping/news")
@Api(tags = "新闻咨询")
public class BookNewsController extends BaseController
{
    @Autowired
    private IBookNewsService bookNewsService;

    /**
     * 查询新闻列表
     */
    @GetMapping("/list")
    @ApiOperation("查询新闻列表")
    public TableDataInfoVo<List<BookNews>> list(GetBookNewsParam getBookNewsParam)
    {
        Page page = GetPageUtil.getPages(getBookNewsParam.getPageNum(),getBookNewsParam.getPageSize(),bookNewsService.selectBookNewsList(getBookNewsParam));
        return getDataTable(page.getRecords(),page.getTotal());
    }

    /**
     * 获取新闻详细信息
     */
    @GetMapping(value = "/{newsId}")
    public MsgResult<BookNews> getInfo(@PathVariable("newsId") Long newsId)
    {
        return success(bookNewsService.selectBookNewsByNewsId(newsId));
    }

    /**
     * 新增新闻
     */
    @Log(title = "新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public MsgResult add(@RequestBody BookNews bookNews)
    {
        return toAjax(bookNewsService.insertBookNews(bookNews));
    }

    /**
     * 修改新闻
     */
    @Log(title = "新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public MsgResult edit(@RequestBody BookNews bookNews)
    {
        return toAjax(bookNewsService.updateBookNews(bookNews));
    }

    /**
     * 删除新闻
     */
    @Log(title = "新闻", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public MsgResult remove(@PathVariable Long[] newsIds)
    {
        return toAjax(bookNewsService.deleteBookNewsByNewsIds(newsIds));
    }
}
